let mongoose = require('./index')

const aisaveSchema = new mongoose.Schema({
    // 关联的图片ID
    imageId: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'aiimg',
        required: true
    },
    // 分析时间
    analysisTime: {
        type: Date,
        default: Date.now
    },
    // 基本信息
    faceCount: {
        type: Number,
        default: 0
    },
    // 性别信息
    gender: {
        gender: String, // 'male' or 'female'
        probability: String
    },
    // 年龄信息
    age: {
        age: Number,
        ageRange: String
    },
    // 表情分析
    expressions: {
        dominant: String, // 主要表情
        confidence: String, // 置信度
        scores: mongoose.Schema.Types.Mixed // 所有表情分数
    },
    // 面部特征
    features: {
        faceShape: String, // 脸型
        eyeDistance: Number, // 眼距
        noseLength: Number, // 鼻长
        mouthWidth: Number, // 嘴宽
        faceDimensions: {
            ratio: Number // 面部比例
        }
    },
    // 黄金比例分析
    goldenRatio: {
        totalScore: Number, // 综合得分
        grade: String, // 评级
        details: {
            // 三庭比例
            threeCourts: {
                score: Number,
                upperRatio: Number,
                middleRatio: Number,
                lowerRatio: Number,
                analysis: String
            },
            // 三眼比例
            threeEyes: {
                score: Number,
                leftEyeRatio: Number,
                eyeGapRatio: Number,
                rightEyeRatio: Number,
                analysis: String
            },
            // 面部总体比例
            faceRatio: {
                score: Number,
                formula: String,
                faceLength: Number,
                faceWidth: Number,
                actualRatio: Number,
                goldenRatio: Number,
                deviation: Number,
                analysis: String
            },
            // 鼻嘴关系
            noseMouthRelation: {
                score: Number,
                actualRatio: Number,
                idealRatio: Number,
                analysis: String
            },
            // 鼻嘴宽度
            noseMouthWidth: {
                score: Number,
                actualRatio: Number,
                idealRatio: Number,
                noseWidth: Number,
                mouthWidth: Number,
                analysis: String
            },
            // 眉眼比例
            eyebrowPosition: {
                score: Number,
                eyebrowEyeRatio: Number,
                symmetry: Number,
                analysis: String
            }
        },
        summary: {
            strengths: [String], // 优势特征
            improvements: [String] // 可优化方面
        }
    },
    // 基础比例分析
    proportions: {
        faceRatio: Number,
        faceRatioGrade: String,
        threeCourtAnalysis: {
            isBalanced: Boolean
        },
        threeEyeAnalysis: {
            isBalanced: Boolean
        }
    },
    // 美容建议（保存为文本，不解析）
    beautifyRecommendations: String,
    // AI智能分析结果
    aiAnalysis: String,
    // 原始分析数据（完整的响应数据）
    rawAnalysisData: mongoose.Schema.Types.Mixed
})

const aisavemodel = mongoose.model('aisave', aisaveSchema, 'aisave')
module.exports = aisavemodel
